<%--
Created by IntelliJ IDEA.
User: 陪你度过漫长岁月
Date: 2022/8/5
Time: 11:42
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增轮播图</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
</head>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<body>
<form class="layui-form" action="${pageContext.request.contextPath}/ShowMainFileServlet" enctype="multipart/form-data" method="post" id="form2">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item" id="divdiv">
                <select class="code-select" name="selectLocation" id="selectLocation">
                    <option value="">请选择</option>
                    <option value="首页-模块1.1">首页-模块1</option>
                    <option value="首页-模块2.2">首页-模块2</option>
                    <option value="首页-模块3.3">首页-模块3</option>
                    <option value="主页-轮播图.4">主页-轮播图</option>
                    <option value="主页-模块1.5">主页-模块1</option>
                </select>
            </div>
            <div class="main-container">
                <div class="layui-form-item" id="divdiv2">
                    <input type="file" name="logo" id="file">
                    <input type="submit"><br>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<%--<div class="mainBox" style="margin-top: 200px">--%>
<%--    位置：<input type="text" name="location" id="location1" value="${sessionScope.location==null ? '无':sessionScope.location}"><br>--%>
<%--    地址：<input type="text" name="pic" id="pic" value="${sessionScope.pic==null ? '无':sessionScope.pic}"><br>--%>
<%--    名字：<input type="text" name="name" id="name" value="${sessionScope.name==null ? '无':sessionScope.name}"><br>--%>
<%--    排序：<input type="text" name="sort" id="sort" value="${sessionScope.sort==null ? '无':sessionScope.sort}"><br>--%>
<%--    图片：<img src="${sessionScope.pic}" alt="" width="270" height="130" id="img">--%>
<%--</div>--%>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>

    if (${sessionScope.index!=null}){
        $("#selectLocation").get(0).selectedIndex = ${sessionScope.index};
    }
<%--    ${sessionScope.remove("index")}--%>
<%--    ${sessionScope.remove("location")}--%>
<%--    ${sessionScope.remove("pic")}--%>
<%--    ${sessionScope.remove("name")}--%>
<%--    ${sessionScope.remove("sort")}--%>

    $("#form1").submit(function () {
        if ($("#selectLocation").val() == "") {
            layer.msg('所有信息均不能为空!', {
                icon: 2,
                time: 2000,//2秒关闭（如果不配置，默认是3秒）
                anim: 6,
                top: 5
            });
            return false
        }
    })
    $("#form2").click(function () {
        let bool = false
        let datas = "";
        if ($("#selectLocation").val() == "") {
            layer.msg('所有信息均不能为空!', {
                icon: 2,
                time: 2000,//2秒关闭（如果不配置，默认是3秒）
                anim: 6,
                top: 5
            });
            return false
        }
        $.ajaxSettings.async = false
        $.post("${pageContext.request.contextPath}/ShowMainAddServlet",
            {
                "location": '${sessionScope.location==null ? '无':sessionScope.location}',
                "pic": '${sessionScope.pic==null ? '无' : sessionScope.pic}',
                "name": '${sessionScope.name==null ? '无' : sessionScope.name}',
                "sort": ${sessionScope.sort==null ? '无' : sessionScope.sort}
            }, function (data) {
                console.log(data)
                datas = data;
                if (data == "true") {
                    ${sessionScope.remove("index")}
                    ${sessionScope.remove("location")}
                    ${sessionScope.remove("pic")}
                    ${sessionScope.remove("name")}
                    ${sessionScope.remove("sort")}
                    parent.layui.table.reload('role-table', {page: {curr: 1}});
                    parent.layer.msg("添加成功!")
                    parent.layer.close(parent.layer.getFrameIndex(window
                        .name)); //关闭当前页
                } else {
                    bool = true
                    layer.msg('请检查参数是否正确!', {
                        icon: 2,
                        time: 2000,//2秒关闭（如果不配置，默认是3秒）
                        anim: 6,
                        top: 5
                    });
                }
            });
        if (bool) {
            return false
        }
    })
</script>
</body>
</html>
